package files;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class FileClient2 {
    public static void main(String[] args) throws IOException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                SocketChannel socketChannel = null;
                int i=0;
                try {
                    socketChannel = SocketChannel.open();
                    socketChannel.connect(new InetSocketAddress("192.168.31.71", 8080));
                    System.out.println("1111111");
                    File file = new File("/home/java/aaa.txt");
                    System.out.println("2222222");
                    FileInputStream fis = new FileInputStream(file);
                    System.out.println("3333333");
                    FileChannel fileChannel = fis.getChannel();
                    System.out.println("55555555");
                    fileChannel.transferTo(0, file.length(), socketChannel);
                    System.out.println("66666666");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        socketChannel.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread.start();

    }
}
